package com.fzrskj.cloud.sdk.mini.server.dic;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fzrskj.cloud.sdk.mini.server.MiniServerBase;
import com.fzrskj.cloud.sdk.mini.server.MiniServerConfig;
import com.fzrskj.cloud.sdk.mini.server.MiniServerResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据字典.
 * Created by sofical on 2020/9/28.
 */
public class DicService extends MiniServerBase {
    /**
     * construct.
     * @param config 微服务配置.
     */
    public DicService(MiniServerConfig config) {
        super(config, "miniServerGetDicList");
    }

    /**
     * 获取数据字典列表.
     * @param dicName 字典名称.
     * @return 字典列表.
     */
    public List<DicItem> getDicList(String dicName) {
        //请求数据.
        Map<String, Object> requestData = new HashMap<>();
        requestData.put("paramId", dicName);

        //请求结果.
        MiniServerResult result = this.post(requestData);

        if (null != result && result.isSuccess()) {
            return JSON.parseArray(JSONObject.toJSONString(result.getData()), DicItem.class);
        }
        return null;
    }
}
